#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    void reverse(vector<int>& nums, int start, int end)
    {
        while (start < end)
        {
            swap(nums[start], nums[end]);
            start++, end--;
        }
    }
    void rotate(vector<int>& nums, int k) {
        k %= nums.size();
        //[0, n-k-1] [n-k, n]
        reverse(nums, 0, nums.size() - k - 1);
        reverse(nums, nums.size() - k, nums.size() - 1);
        reverse(nums, 0, nums.size() - 1);
    }
};